package com.qinxueit.admin.controller;


import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.qinxueit.admin.entity.Sys;
import com.qinxueit.admin.service.SysService;
import com.qinxueit.core.utils.Result;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author wangqinxue
 * @since 2021-08-04
 */
@RestController
@RequestMapping("/sys")
public class SysController {

    @Autowired
    private SysService sysService;

    @GetMapping("/list")
    public Result list(@RequestParam(defaultValue = "1") Integer currentPage){
        Page page = new Page(currentPage,10);
        Page rPage = sysService.page(page, new QueryWrapper<Sys>().orderByDesc("create_time"));
        return Result.success(rPage);
    }

    @GetMapping("/detail/{id}")
    public Result detail(@PathVariable(name = "id") Integer id){
        Sys sys = sysService.getById(id);
        return Result.success(sys);
    }

    @PostMapping("/save")
    public Result save(Sys sys){
        boolean b = sysService.save(sys);
        return Result.success();
    }

    @GetMapping("/del/{id}")
    public Result del(@PathVariable(name = "id") Integer id){
        boolean b = sysService.removeById(id);
        return Result.success();
    }
}
